using Kopernikus.Parsing.GenericActions;
using Kopernikus.Parsing.GenericLexing;
using Kopernikus.Parsing.Lexing;
using NUnit.Framework;

namespace Kopernikus.Parsing.Tests.GenericLexing
{
    [TestFixture]
    public class TestFailOnBadHandlers
    {
        private class L_BadParam
        {
            [LexDefault("x")]
            public string t(string s)
            {
                return s;
            }
        }

        private class L_BadParamCount
        {
            [LexDefault("x")]
            public string t(LexerMatch m1, LexerMatch m2)
            {
                return "";
            }
        }

        private class L_BadReturnValue
        {
            [LexDefault("x")]
            public int t(LexerMatch m)
            {
                return 0;
            }
        }

        private static void TestLexer<TLexer>() where TLexer : new()
        {
            try
            {
                GenericLexer<TLexer, string> lexer = GenericLexer<TLexer, string>.Create(new TLexer());
                Assert.Fail();
            }
            catch (InvalidGenericActionException e)
            {
            }
        }

        public void Test()
        {
            TestLexer<L_BadParam>();
            TestLexer<L_BadParamCount>();
            TestLexer<L_BadReturnValue>();
        }
    }
}